﻿//----设置Cookie------

function setCookie(domain, name, value) {
//    var extime = new Date();
//    extime.setTime(extime.getTime() + 31555360000);
//    var expiryString = ";expires=" + extime.toGMTString();
//    var oldCookieStr = document.cookie;
//    var newCookieStr = "";
//    var oldvalue = encodeURI(getCookie(domain, name)).toLowerCase();
//    var index = document.cookie.indexOf(name + "=" + oldvalue);
//    if (index >= 0)
//        newCookieStr=oldCookieStr.replace(name + "=" + oldvalue, name + "=" + encodeURI(value));
//    else {
//        index = document.cookie.indexOf(domain + "=");
//        if (index >= 0) {
//            var nameIndex = document.cookie.indexOf(name + "=", index + domain.length);
//            if (nameIndex >= 0) { //已经处理过了，
//                var nexNameIndex = document.cookie.indexOf("&", nameIndex + name.length + 1)
//                var searchOldValue = document.cookie.substring(nameIndex + name.length + 1, nexNameIndex - 1);
//                newCookieStr = oldCookieStr.replace(name + "=" + searchOldValue, name + "=" + encodeURI(value)); 
//            }
//            else {
//                newCookieStr = oldCookieStr.replace(domain + "=", domain + "=" + name + "=" + encodeURI(value) + "&");
//            }
//        }
//        else {
//            newCookieStr = oldCookieStr + ";" + domain + "=" + name + "=" + encodeURI(value) ;
//        }
//    }
    //    document.cookie = newCookieStr + expiryString;
    AjaxFunction.SetCookie(domain, name, value);
}
//document.cookie = "";
//----设置Cookie 结束------

//----读取Cookie-------

function getCookie(domain, name) {
    var result = AjaxFunction.GetCookie(domain, name);
    if (result.value != null)
        return result.value.toString();
    return "";
    //return "北京";
//    var CookieFound = false;
//    var start = 0;
//    var end = 0;
//    var CookieString = document.cookie;
//    var i = 0;
//    name = domain + "=" + name; //增加前缀
//    while (i <= CookieString.length) {
//        start = i;
//        end = start + name.length;
//        if (CookieString.substring(start, end) == name) {
//            CookieFound = true;
//            break;
//        }
//        i++;
//    }

//    if (CookieFound) {
//        start = end + 1;
//        end = CookieString.indexOf(";", start);
//        if (end < start)
//            end = CookieString.length;
//        var getvalue = CookieString.substring(start, end);
//        end = getvalue.indexOf("&", 0);
//        if (end < 0)
//            end = getvalue.length;
//        getvalue = getvalue.substring(0, end);
//        return decodeURI(getvalue);
//    }
//    return "";
}

function ResolveCookie() {
    var cookieArray = new Array();
    var cookieStr = document.cookie;
    var cookieDomainValues = cookieStr.Trim().split(";");
    if (cookieDomainValues.length > 0) {
    }
}

function isEnableCookie() {
    try {
        var cookie_helper = new CookieHelper("");
        var test_cookie_name = "test_cookie_name";
        var test_cookie_value = "test_cookie_value";
        var test_cookie_value_ret = "";

        cookie_helper.writeCookie(test_cookie_name, test_cookie_value);
        test_cookie_value_ret = cookie_helper.getCookieValue(test_cookie_name);

        if (test_cookie_value_ret != null) {
            cookie_helper.removeCookie(test_cookie_name);
            return true;
        } else {
            return false;
        }
    } catch (error) {
        return false;
    }
}

//获取用户首次登陆是的省份
function getCurrentProvince() {
    var result = AjaxFunction.getCurrentState();
    if (result.value != null && result.value != "") {
        return result.value;
    }
    return "北京";
}

        
       